package think.in.spring.config;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import think.in.spring.bean.IdBean;
import think.in.spring.bean.QualifierDemo;

/**
 * 限定注册
 * 1. 同一个IdBean有3个id
 * 2. 第二个是主要，用于默认注入
 */
@Configuration
public class QualifierConfig {

    @Bean
    public QualifierDemo qualifierDemo() {
        return  new QualifierDemo();
    }

    @Bean
    public IdBean idBean1() {
        IdBean bean = new IdBean();
        bean.setId(1L);
        return bean;
    }

    @Bean
    @Primary
    public IdBean idBean2() {
        IdBean bean = new IdBean();
        bean.setId(2L);
        return bean;
    }

    @Bean
    public IdBean idBean3() {
        IdBean bean = new IdBean();
        bean.setId(3L);
        return bean;
    }

    @Bean
    @Qualifier("1")
    public IdBean idBean4() {
        IdBean bean = new IdBean();
        bean.setId(4L);
        return bean;
    }
    @Bean
    @Qualifier("2")
    public IdBean idBean5() {
        IdBean bean = new IdBean();
        bean.setId(5L);
        return bean;
    }
}
